// VedioPlayerServerDlg.cpp

#include "stdafx.h"
#include "VedioPlayer.h"
#include "VedioPlayerServerDlg.h"
#include "afxdialogex.h"

VedioPlayerServerDlg* VedioPlayerServerDlg::m_pVPServerDlg = nullptr;

IMPLEMENT_DYNAMIC(VedioPlayerServerDlg, CDialogEx)
BEGIN_MESSAGE_MAP(VedioPlayerServerDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BTN_SERVER_OPEN_TCP, &VedioPlayerServerDlg::OnBnClickedBtnServerOpenTCP)
    ON_BN_CLICKED(IDC_BTN_SERVER_CLOSE_TCP, &VedioPlayerServerDlg::OnBnClickedBtnServerCloseTCP)
    ON_BN_CLICKED(IDC_BTN_SERVER_CLOSE, &VedioPlayerServerDlg::OnBnClickedBtnServerClose)
END_MESSAGE_MAP()

VedioPlayerServerDlg::VedioPlayerServerDlg(CWnd* pParent/* = NULL*/)
    : CDialogEx(VedioPlayerServerDlg::IDD, pParent)
{
}

VedioPlayerServerDlg::~VedioPlayerServerDlg()
{
}

void VedioPlayerServerDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}

void VedioPlayerServerDlg::UnInitialize()
{
    if (m_pVPServerDlg != nullptr)
    {
        delete m_pVPServerDlg;
        m_pVPServerDlg = nullptr;
    }
}

VedioPlayerServerDlg* VedioPlayerServerDlg::GetInstance(CWnd* pParent/* = NULL*/)
{
    if (m_pVPServerDlg == nullptr)
    {
        m_pVPServerDlg = new VedioPlayerServerDlg(pParent);
    }

    return m_pVPServerDlg;
}

BOOL VedioPlayerServerDlg::IsInitialize()
{
    if (m_pVPServerDlg == nullptr)
    {
        return FALSE;
    }

    return TRUE;
}

void VedioPlayerServerDlg::SetCloseCallBack(CLOSE_SERVER_DIALOG_CALLBACK callbackCloseDialog)
{
    m_callbackCloseDialog = callbackCloseDialog;
}

BOOL VedioPlayerServerDlg::PreTranslateMessage(MSG* pMsg)
{
    if(pMsg->message==WM_KEYDOWN)
    {
        if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE))
        {
            UnInitialize();

            return true;
        }
    }

    return CDialogEx::PreTranslateMessage(pMsg);
}

void VedioPlayerServerDlg::OnBnClickedBtnServerOpenTCP()
{
}


void VedioPlayerServerDlg::OnBnClickedBtnServerCloseTCP()
{
}


void VedioPlayerServerDlg::OnBnClickedBtnServerClose()
{
    m_callbackCloseDialog();

    UnInitialize();
}
